<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>添加资源页面</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" th:href="@{/css/x-admin.css}" media="all">

<style type="text/css">
	/* body{
		  font-family: "华文细黑";
		  background:url("https://desk-fd.zol-img.com.cn/t_s1920x1200c5/g5/M00/02/05/ChMkJlbKyIyIPqwEAAoT7kBm98gAALIDwAcn-YAChQG861.jpg") no-repeat;
		  background-size: 100%;
	} */
  
  
 
</style>


</head>

<body  >
<div class="x-body  layui-bg-gray" id="jsonresouredata"  >
  <form class="layui-form"  >
    <div class="layui-form-item">
      <label  class="layui-form-label"> <span class="x-red">*</span>子栏目名称 </label>
      <div class="layui-input-inline">
        <input type="text" id="barListName" name="barListName" required lay-verify="barListName"
                        autocomplete="on" class="layui-input">
      </div>
     
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label"> <span class="x-red">*</span>描述 </label>
      <div class="layui-input-inline">
       <input type="text" id="description" name="description"
                        autocomplete="on" class="layui-input">
      </div>
    </div>
    
    
    <div class="layui-form-item">
      <label  class="layui-form-label"> <span class="x-red">*</span>URL </label>
      <div class="layui-input-inline">
        <input type="text" id="url" name="url" required lay-verify="url"
                        autocomplete="on" class="layui-input">
      </div>
     <span class="x-red">（无参数URL必须带有下划线 '_' ）</span>
    </div>
      
      
    <div class="layui-form-item">
      <label for="L_username" class="layui-form-label"> <span class="x-red">*</span>请选择所属栏目 </label>
      <div class="layui-input-inline" >
        	<select name="bar_id"  >
        		<option>=====选择栏目=====</option>
                 <option  th:each="bar:${Bars}"  th:value="${bar.id}" th:text="${bar.barName}"></option>
            </select>
      </div>
    </div>
      
     
      
      
    

		<div class="layui-form-item">
		      <label for="L_repass" class="layui-form-label"> </label>
		      <button  class="layui-btn" lay-filter="add" lay-submit=""> 增加 </button>
    	</div>
  </form>
</div>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8">
        </script> 
<script th:src="@{/js/x-layui.js}" charset="utf-8">
        </script> 
<script>
            layui.use(['form','layer'], function(){
                $ = layui.jquery;
              var form = layui.form()
              ,layer = layui.layer;
            
            //自定义验证规则
              form.verify({
            	  barListName: function(value){
                  if(value.length < 4){
                    return '子栏目至少得4个字符';
                  }
                }
                ,url: function(value){
                    if(value.length < 4){
                        return '不能为空';
                      }
                    }
              });
              
              //监听提交
              form.on('submit(add)', function(data){
                console.log(data);
                //发异步，把数据提交给后台
                var info;
                $.ajax({
                	url: '/touser/resource',
                	type: 'POST',
                	data: $("#jsonresouredata form").serialize(),//jquery的序列化表单
                	async: false,//默认true 即异步  请求未结束 ajax后面的内容均会执行   但是false下，只有得到success执行成功后面的才会继续判断
                	success:function(result){
                		console.log(result);
                		info=result.content;
                	}
                });//ajax结束
                
        		if(info=="success"){
       			  layer.alert("增加成功", {icon: 6},function () {
       				     
       				   parent.location.reload();
                         // 获得frame索引
                         var index = parent.layer.getFrameIndex(window.name);
                         //关闭当前frame
                         parent.layer.close(index);
                     });
        		}else{
        			 layer.alert("后台数据校验失败,请重新注册", {icon: 7},function () {
                         // 获得frame索引
                         var index = parent.layer.getFrameIndex(window.name);
                         //关闭当前frame
                         parent.layer.close(index);
                     });
        			
        		}//提交判断结束
              
              return false;//必须返回
              });//监听结束
              
            });//表单提交结束
        </script>
</body>
</html>